package com.xk.order.controller;

import com.xk.order.dto.OrderDTo;
import com.xk.order.pojo.Order;
import com.xk.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param orderDTo
     * @return
     */
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderDTo orderDTo){

        ResponseEntity<Long> orderId = ResponseEntity.ok(orderService.createOrder(orderDTo));
        return orderId;


    }

    /**
     * 通过订单id查询订单
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ResponseEntity<Order> queryOrderById(@PathVariable("id") Long id){

        return ResponseEntity.ok(orderService.queryOrderById(id));
    }

    /**
     * 根据订单id生成支付的二维码链接
     * @param orderId
     * @return
     */
    @GetMapping("url/{id}")
    public ResponseEntity<String> createPayUrl(@PathVariable("id") Long orderId){
        return ResponseEntity.ok(orderService.createPayUrl(orderId));



    }
}
